/**
 * @description: sessionStorage Value
 * @param {type: String}
 * @return: [Object,String,null]
 */
export function getSessionStorage(key: string): any {
  let storageData = sessionStorage.getItem(key);
  if (storageData) {
    let storage;
    try {
      storage = JSON.parse(storageData);
    } catch (err) {
      storage = storageData;
    }
    return storage;
  }
  return storageData;
}

/**
 * @description: sessionStorage set Value
 * @param {[key,data]}
 * @return:void
 */
export function setSessionStorage(key: string, data: any) {
  typeof data === "string" ? sessionStorage.setItem(key, data) : sessionStorage.setItem(key, JSON.stringify(data));
}

/**
 * @description: remove sessionStorage key
 * @param { arguments }
 * @return: [Array,undefined]
 */
export function removeSessionStorageKey(...args: string[]) {
  let errArgs: string[] = [];
  args.forEach((item) => {
    typeof item === "string" ? sessionStorage.removeItem(item) : errArgs.push(item);
  });
  return errArgs.length ? { errMsg: "error param", errKey: errArgs } : undefined;
}
